import QtQuick 2.7
import QtQuick.Controls 2.1
import QtQuick.Layouts 1.3

Item {
    id: root

    property alias seekable: slider.enabled
    property int position: 0
    property int duration: 3600
    signal playSeek(int pos);

    function formatTime(time) {
        var dateTime = new Date(0, 0, 0, 0, 0, 0, time);
        if(time >= 3600 * 1000)
            return Qt.formatTime(dateTime,"hh:mm:ss")
        else
            return Qt.formatTime(dateTime,"mm:ss")
    }

    RowLayout {
        anchors.fill: parent
        spacing: 16

        Label {
            text: formatTime(position)
        }

        Slider {
            id: slider
            Layout.fillWidth: true
            Layout.fillHeight: true
            from: 0
            to: root.duration
            onValueChanged: {
                if(slider.pressed)
                    root.playSeek(slider.value);
            }
        }

        Label {
            text: formatTime(duration)
        }
    }

    Binding { target: slider; property: "value"; value: root.position; when: !slider.pressed }
//    Binding { target: root; property: "position"; value: slider.value; when: slider.pressed }
}
